package com.ft.springboottravel.controller;


import com.ft.springboottravel.bean.Banner;
import com.ft.springboottravel.service.BannerService;
import com.ft.springboottravel.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("banner")
public class BannerContorller {

    @Autowired
    private BannerService bannerService;

    @RequestMapping("toBannerList")
    public String toBannerList(Integer routeId, Integer current, Model model){
        Integer currentPage = 1;
        if(current!=null){
            currentPage=current;
            model.addAttribute("currentPage", currentPage);
        }
        if(routeId!=null){
            model.addAttribute("routeId",routeId);
        }
        Pager<Banner> bannerPager = bannerService.selectBannerAll(routeId, currentPage);
        List<Banner> list =bannerPager.getList();
        for (Banner banner : list) {
            System.out.println(banner);
        }
        model.addAttribute("Pager", bannerPager);
        return "banner/list";
    }


}
